# include<iostream>
# include<vector>
# include"NewtonFormula.h"
# include"Function.h"
# define _USE_MATH_DEFINES
# include<cmath>

using namespace::std;

/**
* @brief 一个仿函数类，用于计算 f(x)
* 
*/
class func : public Function
{
public:
    double operator() (const double & _x) const
    {
        return (1 / (1 + 25 * _x * _x));
    }
};

/**
* @brief 生成[-5,5]上对应数量的 Chebyshev 插值点
* 
*/
vector<double> ChebyshevPoint(int n)
{
    vector<double> point;
    double xi;
    for (int k = 1; k <= n; k++)
    {
        xi = cos((2.0 * k - 1) / (2.0 * n) * M_PI);
        point.push_back(xi);
    }
    return point;
}

/**
* @brief 打印对应的向量
* 
*/
void PrintVector(vector<double> vec)
{
    for (int i = 0; i < vec.size(); i++)
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

int main()
{
    func f;

    // 分为不同的 n 计算对应的牛顿插值多项式
    for (int n = 5; n <= 20; n += 5)
    {
        cout << "n = " << n << endl;
        vector<double> point(ChebyshevPoint(n));
        PrintVector(point);
        NewtonFormula Solver(f, point);
        Solver.PrintPol();
        Solver.PrintPolCoff();
    }
    return 0;
}